//
//  EmoticonPackage.swift
//  SinaWebo
//
//  Created by mis on 16/3/23.
//  Copyright © 2016年 mis. All rights reserved.
//

import UIKit

class EmoticonPackage: NSObject {
    
    lazy var emoticonList = [Emoticon]()
    /// 表情分组的包名
    var id: String?
    /// 表情分组中文名称
    var group_name_cn: String?
    
    /**
        每隔20个按钮需要一个删除按钮
        页面表情不足21个需要补足
    */
    init(id: String, name: String, emoticons: [[String: String]]) {
        self.id = id
        self.group_name_cn = name
        super.init()
        var index = 0
        for dict in emoticons {
            let e = Emoticon(id: id, dict: dict)
            emoticonList.append(e)
            index++
            if index == 20 {
                let deleteEmoticon = Emoticon(isRemove: true)
                emoticonList.append(deleteEmoticon)
                index = 0
            }
        }
        insertEmptyEmoticon()
    }
    
    private func insertEmptyEmoticon() {
        let count = emoticonList.count % 21
        if  count == 0 {
            return
        }
        
        for _ in count..<20 {
            let emptyEmoticon = Emoticon(isEmpty: true)
            emoticonList.append(emptyEmoticon)
        }
        let deleteEmoticon = Emoticon(isRemove: true)
        emoticonList.append(deleteEmoticon)
    }
}
